package cn.itcast.order.service;

import cn.itcast.gateway.clients.UserClient;
import cn.itcast.gateway.pojo.User;
import cn.itcast.order.mapper.OrderMapper;
import cn.itcast.order.pojo.Order;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class OrderService {

    @Autowired
    private OrderMapper orderMapper;

    @Autowired
    private UserClient userClient;

    public Order queryOrderById(Long orderId) {
        // 1.查询订单
        Order order = orderMapper.findById(orderId);

        //2.查询用户
//        String url="http://localhost:8081/user/"+order.getUserId();
//        String url="http://userservice/user/"+order.getUserId();//通过服务名拼接地址-通过restTemplate查询其他服务数据
//        User user = restTemplate.getForObject(url, User.class);

        //通过feign去调用微服务
        User user = userClient.findById(order.getUserId());

        //返回结果加入用户信息
        order.setUser(user);

        // 4.返回
        return order;
    }
}
